package com.wcarmon.life.vo {

 	import com.adobe.cairngorm.vo.IValueObject;
 	import mx.utils.ObjectUtil;
 	import mx.controls.Alert;
	import com.wcarmon.utils.Utils;
	
	public class ReviewVO implements IValueObject {
		include "../../includes/loggerSnippet.as";
		public static var sLog : ILogger = Log.getLogger("com.wcarmon.life.vo.ReviewVO");
		
		public function toString() : String{
			var s : String = "ReviewVO[id=" + id;
			s += ", label=" + label;
			s += ", lastCompletedOn=" + lastCompletedOn;
			s += ", url=" + url;
			s += "]";
			return s;
		}
		
		[Bindable]
		public var id : Number;
		
		[Bindable]
		public var label : String;
		
		[Bindable]
		public var output : String;
		
		[Bindable]
		public var lastCompletedOn : String;	//date
		
		[Bindable]
		public var sort : Number;
		
		[Bindable]
		public var url : String;
		
		[Bindable]
		public var isDaily : Boolean = false;
		
		[Bindable]
		public var isWeekdayOnly : Boolean = false;
		
		[Bindable]
		public var isWeekly : Boolean = false;
		
		[Bindable]
		public var isMonthly : Boolean = false;
		
		[Bindable]
		public var isQuarterly : Boolean = false;
		
		[Bindable]
		public var isYearly : Boolean = false;

		

		public function ReviewVO() {
		}
		
		public function urlIsExternal() : Boolean {
			var urlIsExternal : Boolean = ( this.url.indexOf('http:') == 0 );
			return urlIsExternal;
		}
		
		public static function makeReviewFromObject( o : Object ) : ReviewVO{
			//sLog.debug('Making a ReviewVO from server review hashmap');
			
			var r : ReviewVO = new ReviewVO();
			r.id = o.id;
			r.label = o.label;
			r.output = o.output;
			r.lastCompletedOn = o.lastCompletedOn;
			r.sort = o.sort;
			r.url = o.url;
			r.isDaily = (o.isDaily != 0);
			r.isWeekdayOnly = (o.isWeekdayOnly != 0);
			r.isWeekly = (o.isWeekly != 0);
			r.isMonthly = (o.isMonthly != 0);
			r.isQuarterly = (o.isQuarterly != 0);
			r.isYearly = (o.isYearly != 0);
			return r;		
		}		
		
        public static function reviewDateIsTooOld( dateType : String, dateStr : String ) : Boolean {
        	switch( dateType ){
        		case 'daily':	return ( dateStr < Utils.nDaysAgoStr(2) ); 
        		case 'weekly':  return ( dateStr < Utils.nDaysAgoStr(7) );
        		case 'monthly':  return ( dateStr < Utils.nDaysAgoStr(30) );	//Givon - fix - be more accurate
        		case 'quarterly':  return ( dateStr < Utils.nDaysAgoStr(90) );	//Givon - fix - be more accurate
        		case 'yearly':  return ( dateStr < Utils.nDaysAgoStr(365) );	
        		default:
        			sLog.fatal("Code error: can't find review-type=" + dateType);
        			Alert.show("Code error in ReviewVO.reviewDateIsTooOld - fix review type: '"+ dateType +"'");
        	}	
        	return true;
        }
		
	}
}